var player = null;

$(function() {
    var txt = $('#txtSearch');

    $('#btnSearch').click(function() {
        if (txt.val().trim().length > 0) {
            var img = $(this);
            $.get('Processor.ashx?t=' + Math.random(), {
                m: 'Search',
                d: txt.val().trim()
            },
            function(r) {
                if (r.length > 0) {
                    $('#results').html(r);
                    $('#results li:even').addClass('alt');
                }
                else
                    $('#results').html('Your search <b>' + $('#txtSearch').val().trim() + '</b> did not match any records.');

                img.removeClass('loading');
            }, 'html');
            img.addClass('loading');
        }
        else {
            alert('Please enter a Station / Genre to search');
            txt.focus();
        }
    });

    $('.menu').click(function(e) {
        alert(e.target.alt.toUpperCase() + '?');
    });

    swfobject.embedSWF('player.swf', 'ctnPlayer', '320', '20', '9.0.124', false, {
        file: 'http://193.164.132.203:8200/;stream.nsv',
        type: 'sound',
        autostart: 'false',
        backcolor: '8798A8',
        frontcolor: '2D4458',
        lightcolor: '5E2221'
    }, {
        allowfullscreen: 'false',
        allowscriptaccess: 'always'
    }, {
        id: 'thePlayer',
        name: 'thePlayer'
    });

    txt.focus();
});

function playerReady(obj) {
    player = document.getElementById(obj.id);
};

function GetRadio(id) {
    $.get('Processor.ashx?t=' + Math.random(), {
        m: 'Radio',
        d: id
    },
    function(r) {
        player.sendEvent('STOP');
        player.sendEvent('LOAD', { file: r + '/;stream.nsv', type: 'sound' })
        player.sendEvent('PLAY', 'true');
    }, 'html');
}

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, '');
}